package com.woniu.zsd.shopping.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniu.zsd.common.util.Result;
import com.woniu.zsd.shopping.dto.QueryProductOrderDto;
import com.woniu.zsd.shopping.form.AddProductOrderForm;
import com.woniu.zsd.shopping.form.AddReceiverInfoForm;
import com.woniu.zsd.shopping.model.AddReceiverInfoParam;
import com.woniu.zsd.shopping.param.AddProductOrderParam;
import com.woniu.zsd.shopping.service.ProductOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangtao
 * @since 2025年02月18日
 */
@RestController
@RequestMapping("/productOrder")
@Api(tags = "商品订单类接口")
public class ProductOrderController {

    @Resource
    private ProductOrderService productOrderService;
    @PostMapping("/addProductOrder")
    @ApiOperation("新增商品订单")
    public Result addProductOrder(@RequestBody AddProductOrderForm form) throws Exception {
        productOrderService.addProductOrder(BeanUtil.toBean(form, AddProductOrderParam.class));
        return Result.success("新增订单成功");
    }

    @PostMapping("/updateProductOrderStatus")
    @ApiOperation("修改订单状态")
    public Result updateProductOrderStatus(Integer productOrderId,Integer status ) throws Exception {
        productOrderService.updateProductOrderStatus(productOrderId,status);
        return Result.success("修改订单状态成功");
    }

    @PostMapping("/addReceiverInfo")
    @ApiOperation("添加收货人信息")
    public Result addReceiverInfo(@RequestBody AddReceiverInfoForm form) throws Exception {
        productOrderService.addReceiverInfo(BeanUtil.toBean(form, AddReceiverInfoParam.class));
        return Result.success("添加收货人信息成功");
    }

    @PostMapping("/queryProductOrder")
    @ApiOperation("查询订单")
    public Result queryProductOrder(Integer productOrderId) throws Exception {
        QueryProductOrderDto dto = productOrderService.queryProductOrder(productOrderId);
        return Result.success("查询订单信息成功",dto);
    }




}

